Release 10.1A: OpenEdge Development:
Progress 4GL Reference


ERROR-STATUS system handle

A handle to error information on the last statement executed with the NO-ERROR option.

Syntax

ERROR-STATUS [ :attribute | :method ] 

attribute

Specifies an attribute of the ERROR-STATUS handle.

method

Specifies a method of the ERROR-STATUS handle.

Attributes

   

Methods

Examples

The following example uses the NO-ERROR and the ERROR-STATUS handle extensively to demonstrate when ERROR-STATUS attributes are reset:

r-errst1.p 
CONNECT "db-xyz" NO-ERROR.
RUN chk-connect NO-ERROR.
IF ERROR-STATUS:ERROR
THEN MESSAGE "Run statement failed.".

PROCEDURE chk-connect.
DEFINE VARIABLE connect-ok AS LOGICAL INITIAL TRUE NO-UNDO.

   IF ERROR-STATUS:ERROR
   THEN DO:
       MESSAGE "Connect failed.".
       connect-ok = FALSE NO-ERROR.
       IF ERROR-STATUS:ERROR
       THEN MESSAGE "Assignment failed.".
   END.
   
   IF connect-ok
        THEN RETURN "OK".
   ELSE RETURN "FAILED".
END PROCEDURE. 

Within the internal procedure, chk-connect, the first reference to ERROR-STATUS:ERROR returns status on the CONNECT statement from the main procedure. The second reference returns status on the assignment statement. The reference to ERROR-STATUS:ERROR in the main procedure returns status on the RUN statement. Note that the ERROR-STATUS attributes are set only after the statement with NO-ERROR completes. Therefore the references in the internal procedure are not affected by the RUN statement itself.

The following procedure accepts a character string value and lets you convert it to one of several data types. The internal convert procedure attempts the conversion. If the conversion is successful, it displays the converted value. If the conversion is unsuccessful, the ERROR-STATUS handle holds error information. After running convert, the CHOOSE trigger checks ERROR-STATUS:ERROR and ERROR-STATUS:NUM-MESSAGES to determine if error information is available. If it is, it lets you view this information.

r-errsts.p
DEFINE VARIABLE txt AS CHARACTER FORMAT "X(20)" NO-UNDO.
DEFINE VARIABLE i   AS INTEGER NO-UNDO.

DEFINE BUTTON b_int  LABEL "Integer".
DEFINE BUTTON b_date LABEL "Date".
DEFINE BUTTON b_dec  LABEL "Decimal".
DEFINE BUTTON b_log  LABEL "Logical".
DEFINE BUTTON b_quit LABEL "Quit" AUTO-ENDKEY. 
  
DEFINE FRAME butt-frame
  b_int b_date b_dec b_log b_quit
  WITH CENTERED ROW SCREEN-LINES - 2.DEFINE FRAME get-info
  txt LABEL "Enter Data To Convert"
  WITH ROW 2 CENTERED SIDE-LABELS TITLE "Data Conversion - Error Check".
  
ON CHOOSE OF b_int, b_date, b_dec, b_log IN FRAME butt-frame
DO:
  IF txt:MODIFIED IN FRAME get-info THEN
  DO:
    ASSIGN txt.
    RUN convert(txt).
    IF ERROR-STATUS:ERROR AND ERROR-STATUS:NUM-MESSAGES > 0 THEN
    DO:
      MESSAGE ERROR-STATUS:NUM-MESSAGES 
       " errors occurred during conversion." SKIP 
       "Do you want to view them?" 
       VIEW-AS ALERT-BOX QUESTION BUTTONS YES-NO 
       UPDATE view-errs AS LOGICAL.
       
      IF view-errs THEN
      DO i = 1 TO ERROR-STATUS:NUM-MESSAGES:
        MESSAGE ERROR-STATUS:GET-NUMBER(i)
                ERROR-STATUS:GET-MESSAGE(i).
      END.
    END.
  END. /* IF txt:MODIFIED... */
  ELSE
    MESSAGE "Please enter data to be convert and then choose the type"
            "of conversion to perform."
      VIEW-AS ALERT-BOX MESSAGE BUTTONS OK.           
END.
  
ENABLE ALL WITH FRAME butt-frame.
ENABLE txt WITH FRAME get-info.
WAIT-FOR CHOOSE OF b_quit IN FRAME butt-frame FOCUS txt IN FRAME get-info. 
/***** Internal Procedure "convert" *****/
PROCEDURE convert:
  DEFINE INPUT PARAMETER x AS CHARACTER NO-UNDO.
  DEFINE VARIABLE i  AS INTEGER   NO-UNDO.
  DEFINE VARIABLE d  AS DECIMAL   NO-UNDO.
  DEFINE VARIABLE dd AS DATE      NO-UNDO.
  DEFINE VARIABLE l  AS LOGICAL   NO-UNDO.
  
  message self:label.
  
  CASE SELF:LABEL:
    WHEN "Integer" THEN DO:
      ASSIGN i = INT(x) NO-ERROR.
      MESSAGE "Converted value:" i.
    END.
    WHEN "Date" THEN DO:
      ASSIGN dd = DATE(INT(SUBSTR(x,1,2)),
                       INT(SUBSTR(x,4,2)),
                       INT(SUBSTR(x,7)) ) NO-ERROR.
      MESSAGE "Converted value:" dd.
    END. 
    WHEN "Decimal" THEN DO:
      ASSIGN d = DEC(x) NO-ERROR.
      MESSAGE "Converted value:" d.
    END.
    WHEN "Logical" THEN DO:
      ASSIGN l = x = "yes" OR x = "true" NO-ERROR.
      MESSAGE "Converted value:" l.
    END.
  END.    
END. 

Notes

See also

SOAP-fault object handle, SOAP-fault-detail object handle


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095